package com.gagakuai.executor;

import com.gagakuai.mapping.BoundSql;
import com.gagakuai.mapping.MappedStatement;
import com.gagakuai.session.Configuration;
import com.gagakuai.session.ResultHandler;
import com.gagakuai.session.RowBounds;
import com.gagakuai.statement.StatementHandler;
import org.apache.commons.logging.Log;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/*
 * @program: common-starters
 * @description: 简单的查询
 * @author: houhong
 * @create: 2023-07-01 20:58
 */
public class SimpleExecutor extends BaseExecutor {

    private Executor wrapper;

    @Override
    public <E> E doQuery(MappedStatement ms, Object obj, RowBounds rs, ResultHandler resultHandler, BoundSql boundSql) {

        Statement stmt = null;

        Configuration configuration = ms.getConfiguration();
        // 获取StatementHandler对象
        StatementHandler handler = configuration.newStatementHandler(wrapper, ms, obj, rs, resultHandler, boundSql);
        // 设置Statement
        stmt = prepareStatement(handler,ms.getStatementLog());

        handler.

        return null;
    }

    /*
     * @param statementLog:日志
     * @param handler         :处理
     * @return {@link Statement}
     * @Author houhong
     * @Description 获取处理
     * @Date 9:18 下午 2023/7/1
     */
    private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {

        Statement stmt = null;
        Connection connection = getConnection(statementLog);
        //获取链接
        stmt = handler.prepare(connection, transaction.getTimeout());
        // 设置参数
        handler.parameterize(stmt);
        return stmt;
    }
}